import Vue from 'vue'
import Router from 'vue-router'

import Index from '@/pages/Index'
import Login from '@/pages/Login'
import cms from '@/pages/AGV'
import I29 from '@/pages/I29'
import Todo from '@/pages/Todo'
import TodoCopy from '@/pages/TodoCopy'
import Home from "../pages/Home";
import Test from '@/pages/test'
import PoL from '@/pages/PictureOrLight'
import Parameter from '@/pages/Parameter'
import Kernel from '@/pages/Kernel'
import jl_control from '@/pages/jl_control'
import jl_task from '@/pages/jl_task'
import jl_card from '@/pages/jl_card'
import jl_shaker from '@/pages/jl_shaker'
import tof_guide from  '@/pages/tof_tasklist'
import tof_gimbalguide from  '@/pages/tof_gimbalguide'
import tof_parameter from '@/pages/tof_Parameter'
import tof_tasklist from  '@/pages/tof_tasklist'

// import tof_gimbalguide from  '@/pages/tof_tasklist'

Vue.use(Router)

/* const originalReplace = Router.prototype.replace
Router.prototype.replace = function replace (location) {
  return originalReplace.call(this, location).catch(err => err)
} */

const router = new Router({
    mode: 'history',
    routes: [
        {
            path: '/',
            name: 'index',
            redirect: '/tof_gimbalguide',
            component: Index,
            children: [

                { 
                    path: 'test',
                    name: 'test',
                    component: Test

                },
                {
                    path: 'home',
                    name: 'home',
                    component: Home,
                    meta: {
                        title: '首页'
                    }
                },
                {
                    path: 'tasklist',
                    name: 'tasklist',
                    component: tof_guide,
                    meta: {
                        title: '设备控制'
                    }
                },
                {
                    path: 'tof_gimbalguide',
                    name: 'tof_gimbalguide',
                    component:tof_gimbalguide,
                    meta: {
                        title: '设备控制'
                    }
                },
                {
                    path: 'tof_tasklist',
                    name: 'tof_tasklist',
                    component:tof_tasklist,
                    meta: {
                        title: '设备控制'
                    }
                },
                {
                    path: 'tof_management',
                    name: 'tof_management',
                    component:tof_parameter,
                    meta: {
                        title: 'tof参数管理'
                    }
                },
                {
                    path: 'jl_control',
                    name: 'jl_control',
                    component: jl_control,
                    meta: {
                        title: '设备控制'
                    }
                },

                {
                    path: 'jl_task',
                    name: 'jl_task',
                    component: jl_task,
                    meta: {
                        title: '任务列表'
                    }
                },
                {
                    path: 'jl_card',
                    name: 'jl_card',
                    component: jl_card,
                    meta: {
                        title: '任务列表'
                    }
                },

                {
                    path: 'jl_shaker',
                    name: 'jl_shaker',
                    component: jl_shaker,
                    meta: {
                        title: '抖动台'
                    }
                },
                {
                    path: 'cms',
                    name: 'cms',
                    component: cms,
                    meta: {
                        title: 'AGV控制'
                    }
                },
                {
                    path: 'PoL',
                    name: 'PoL',
                    component: PoL,
                    meta: {
                        title: '图卡及补光光源控制'
                    }
                },
                {
                    path: 'KM',
                    name: 'KM',
                    component: I29,
                    meta: {
                        title: 'I29控制'
                    }
                    
                },
                {
                    path: 'kernel',
                    name: 'kernel',
                    component: Kernel,
                    meta: {
                        title: 'Kernel控制'
                    }
                    
                },
                {
                    path: 'todo',
                    name: 'todo',
                    component: Todo,
                    meta: {
                        title: '任务管理'
                    }
                },
                {
                    path: 'parameter',
                    name: 'parameter',
                    component: Parameter,
                    meta: {
                        title: '参数管理'
                    }
                },
            ]
        },

        {
            // 登录页面
            path: '/login',
            name: 'login',
            component: Login
        }
    ]
});
router.beforeEach((to, from, next) => {
        let token = localStorage.getItem("token")
        if (to.path == '/login' && !token) {//登陆页面，直接走
            next()

        } else if (!token) {  //token不存在，跳转到登陆页面
            next({path: '/login'})
        } else {
            next()
        }
    }
)
;

export default router;
